﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace ServiceManager.TFSIntegration
{
    public class TFSBugData :  INotifyPropertyChanged
    {
        private  string description;
        private  string id;
        private  string title;
     
        private KeyValuePair<Guid, string> collectionValue;
        private KeyValuePair<int, string> projectValue;

        private bool includeCommentLog;

        public TFSBugData(string id, string title, string description)
        {
            ID = id;
            Title = title;
            Description = description;
            var tfsSettings = TFSSettings.Get();
            if (string.IsNullOrEmpty(tfsSettings.TFSUrl)) 
                throw new InvalidOperationException("The admin settings have not be configured");
            TFSService.Inititalize(tfsSettings.TFSUrl);
        }

        public string ID
        {
            get { return id; }
            set {
                if (id == value) return;
                id = value;
                NotifyPropertyChanged("ID");
            }
        }

        public string Title
        {
            get { return title; }
            set
            {
                if (title == value) return;
                title = value;
                NotifyPropertyChanged("Title");
            }
        }

        public string Description
        {
            get { return description; }
            set
            {
                if (description == value) return;
                description = value;
                NotifyPropertyChanged("Description");
            }
        }


        public KeyValuePair<Guid,string> CollectionValue
        {
            get { return collectionValue; }
            set
            {
                collectionValue = value;
                NotifyPropertyChanged("CollectionValue");
            }
        }

        public KeyValuePair<int, string> ProjectValue
        {
            get { return projectValue; }
            set
            {
                projectValue = value;
                NotifyPropertyChanged("ProjectValue");
            }
        }


        public Guid CollectionId
        {
            get
            {
               return collectionValue.Key;
            }
           
        }

        public int ProjectId
        {
            get { return projectValue.Key; }
        }

        public bool IncludeCommentLog
        {
            get { return includeCommentLog; }
            set
            {
                if (includeCommentLog != value)
                {
                    includeCommentLog = value;
                    NotifyPropertyChanged("IncludeCommentLog");
                }
            }
        }



        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        private void NotifyPropertyChanged(string info)
        {
            PropertyChangedEventHandler propertyChanged = PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }
}